<%--
   dictColumn
   Copyright (c) 2015 ISPERP
   Version : 1.0.0
 --%>
<%@tag import="itsm.isperp.framework.utils.JsonBuilder"%>
<%@tag import="itsm.isperp.module.entity.app.AppDict"%>
<%@tag import="java.util.List"%>
<%@tag import="itsm.isperp.module.service.app.AppDictService"%>
<%@tag import="itsm.isperp.framework.core.context.ContextHolder"%>
<%@ tag language="java" pageEncoding="UTF-8"
	trimDirectiveWhitespaces="true"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ attribute name="title" required="true" type="java.lang.String"
	description="头部标题(th)."%>
<%@ attribute name="name" required="true" type="java.lang.String"
	description="为Grid中的每个列设置唯一的名称，这是一个必需选项。"%>
<%@ attribute name="index" required="false" type="java.lang.String"
	description="设置排序时所使用的索引名称，这个index名称会作为sidx参数（prmNames中设置的）传递到Server。"%>
<%@ attribute name="label" required="false" type="java.lang.String"
	description="当jqGrid的colNames选项数组为空时，为各列指定题头。如果colNames和此项都为空时，则name选项值会成为题头。"%>
<%@ attribute name="width" required="false" type="java.lang.String"
	description="设置列的宽度"%>
<%@ attribute name="align" required="false" type="java.lang.String"
	description="对其方式(默认为左侧对齐)."%>
<%@ attribute name="sortable" required="false" type="java.lang.Boolean"
	description="是设置该列是否可以排序，默认为true。"%>
<%@ attribute name="search" required="false" type="java.lang.Boolean"
	description="设置该列是否可以被列为搜索条件，默认为true。"%>
<%@ attribute name="fixed" required="false" type="java.lang.Boolean"
	description="列宽度是否要固定不可变"%>
<%@ attribute name="resizable" required="false" type="java.lang.Boolean"
	description="设置列是否可以变更尺寸，默认为true。"%>
<%@ attribute name="typeCode" required="true" type="java.lang.String"
	description="字典编码"%>
<%@ attribute name="showTitle" required="false" type="java.lang.String"
	description="字典编码"%>


<c:set var="formatoptions" scope="request" />

<c:choose>
	<c:when test="${empty columns}">
		<c:set var="columns" value="${name}" scope="request" />
	</c:when>
	<c:otherwise>
		<c:set var="columns" value="${columns},${name}" scope="request" />
	</c:otherwise>
</c:choose>

<c:if test="${empty formatoptions}">
	<c:set var="formatoptions" value="{}" scope="request" />
</c:if>
<jsp:doBody />
<c:choose>
	<c:when test="${empty colNames}">
		<c:set var="colNames" value="'${title}'" scope="request" />
	</c:when>
	<c:otherwise>
		<c:set var="colNames" value="${colNames},'${title}'" scope="request" />
	</c:otherwise>
</c:choose>
<c:choose>
	<c:when test="${empty colModel}">
		<c:set var="colModel" value="{name:'${name}'" scope="request" />
	</c:when>
	<c:otherwise>
		<c:set var="colModel" value="${colModel},{name:'${name}'"
			scope="request" />
	</c:otherwise>
</c:choose>

<c:if test="${not empty index}">
	<c:set var="colModel" value="${colModel},index:'${index}'"
		scope="request" />
</c:if>
<c:if test="${not empty label}">
	<c:set var="colModel" value="${colModel},label:'${label}'"
		scope="request" />
</c:if>
<c:if test="${not empty width}">
	<c:set var="colModel" value="${colModel},width:'${width}'"
		scope="request" />
</c:if>
<c:if test="${not empty align}">
	<c:set var="colModel" value="${colModel},align:'${align}'"
		scope="request" />
</c:if>
<c:if test="${not empty sortable}">
	<c:set var="colModel" value="${colModel},sortable:${sortable}"
		scope="request" />
</c:if>
<c:if test="${not empty search}">
	<c:set var="colModel" value="${colModel},search:${search}"
		scope="request" />
</c:if>


<c:if test="${fixed eq true}">
	<c:set var="colModel" value="${colModel},fixed:true" scope="request" />
</c:if>
<c:set var="showTitle" value="${showTitle eq true?true:false }" />
<%
	AppDictService appDictService = ContextHolder
			.getSpringBean("appDictService");

	List<AppDict> dicts = appDictService.findByType(typeCode);
	String dictsJson = JsonBuilder.buildNormalBinder().toJson(dicts);
%>

<c:set var="dictsJson"><%=dictsJson%></c:set>

<c:set var="colModel"
	value="${colModel},formatter:function(cellvalue, options, rowObject){return isperp.formatDict(cellvalue, options, rowObject,${dictsJson },${showTitle },'${name }','${title }');}"
	scope="request" />

<c:set var="colModel" value="${colModel}}" scope="request" />
